package com.k.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.FoodKind;
import com.k.demo.entity.PowerDistribution;
import com.k.demo.service.PowerDistributionService;
import com.k.demo.service.PowerService;

@CrossOrigin
@RestController
@RequestMapping("power")
public class PowerController {
	@Autowired
	private PowerService powerService;
	@Autowired
	private PowerDistributionService powerdistributionService;
	
	@RequestMapping("/all")
	public Object all(){
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("powerList", powerService.getAll());
		return map;
		
	}
	
	@RequestMapping("/queryuser")
	public Object quetyUser(@RequestBody Map<String,Object> map){
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		PageHelper.startPage((int)map.get("pageNum"), (int)map.get("pageSize"));
		
		List<PowerDistribution> foodkindlist = powerdistributionService.getPowerDistributeByPowerId((Integer)map.get("power_id"));
		
		PageInfo pageinfo =new PageInfo<>(foodkindlist,(int)map.get("pageSize"));
		
		rmap.put("userList", pageinfo);
		
		return rmap;
		
	}
	
	
}
